import axios from '../utils/axios'
import { useUserStore } from '../stores/user'

export interface UserInfo {
  id: number
  username: string
  roles: string[]
  createTime: string
}

export interface SystemInfo {
  javaVersion: string
  osName: string
  osVersion: string
  totalMemory: number
  freeMemory: number
  availableProcessors: number
}

export interface DashboardStats {
  totalUsers: number
  roleDistribution: Record<string, number>
  systemInfo: SystemInfo
  userList: UserInfo[]
}

export const getDashboardStats = async (): Promise<DashboardStats> => {
  const userStore = useUserStore()
  

  let endpoint = '/stats'
  if (userStore.isAdmin) {
    endpoint = '/admin/stats'
  }

  
  const response = await axios.get<DashboardStats>(`/api/dashboard${endpoint}`)
  return response.data
} 